/**
 * Copyright 2004 - 2007 Blue Bamboo International Inc. 
 *           All rights reserved.
 *
 *
 * Blue Bamboo PROPRIETARY/CONFIDENTIAL.
 *
 */

package com.bluebamboo.bluetools.pingpang.connection;

import java.net.InetSocketAddress;

import org.apache.mina.transport.socket.SocketAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import com.bluebamboo.bluetools.pingpang.bean.SocketServerBean;

/**
 * DOCME
 * 
 * @author tanxuqing
 * @date Sep 13, 2009
 * @since
 */
public class SocketServerConnectionHandler extends AbstractConnectionHandler<SocketServerBean> {

    private SocketAcceptor acceptor;

    /**
     * @param connectonBean
     */
    public SocketServerConnectionHandler(SocketServerBean connectonBean) {
        super(connectonBean);
    }

    public void connect() throws Exception {
    	super.connect();
        acceptor = new NioSocketAcceptor();
        SocketServerBean connBean = getConnectionBean();
        acceptor.setHandler(getIoHandler());
        acceptor.bind(new InetSocketAddress(connBean.getPort()));
    }

    public void disconnect() throws Exception {
    	super.disconnect();
        SocketServerBean connBean = getConnectionBean();
        acceptor.unbind(new InetSocketAddress(connBean.getPort()));
    }

}
